//
//  AllGoodHomeController.m
//  HomeDecoration
//
//  Created by xalo on 16/2/29.
//  Copyright © 2016年 美家项目组. All rights reserved.
//

#import "AllGoodHomeController.h"
#import "HomeHelper.h"
#import "AllGoodHomeCell.h"
#import "HomeModel.h"

@interface AllGoodHomeController ()

@end

@implementation AllGoodHomeController

static NSString * const reuseIdentifier = @"cell1";

- (void)viewDidLoad {
    [super viewDidLoad];
 self.title=@"所有好家";
    [self setLayout];

    [self.collectionView registerNib:[UINib nibWithNibName:@"AllGoodHomeCell" bundle:nil] forCellWithReuseIdentifier:@"cell1"];
    //网络请求数据
    [[HomeHelper sharedHomeHelper] fetchDataWithUrl:kHome block:^{
        [self.collectionView reloadData];
    }];
    [self setLeftBarbutton];
    
    // Do any additional setup after loading the view.
}
//设置自动布局
-(void)setLayout
{
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing=10;
    layout.minimumInteritemSpacing=10;
    layout.sectionInset=UIEdgeInsetsMake(10, 10, 10,10);
    CGFloat width=([UIScreen mainScreen].bounds.size.width-30)/2;
    CGFloat heigt=1.5*width;
    layout.itemSize=CGSizeMake(width, heigt);
    self.collectionView.collectionViewLayout=layout;

}
//设置做导航按钮
-(void)setLeftBarbutton
{
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"<返回" style:(UIBarButtonItemStylePlain) target:self action:@selector(backToHomeVC)];
    self.navigationController.navigationBar.tintColor=[UIColor blackColor];
    
}
-(void)backToHomeVC
{
    [self.navigationController popToRootViewControllerAnimated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [[HomeHelper sharedHomeHelper] homeModelArrayCount];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    AllGoodHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
    HomeModel *model=[[HomeHelper sharedHomeHelper] returnHomeModelWithIndex:indexPath.item];
    [cell setContentWithModel:model];
    
    
    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
